<template>
  <div class="data-list" :style="{ 'max-height': maxHeight }">
    <div v-for="(item, index) in resData" class="data-item">
      <div
        :class="item?.reported ? 'detail-header detail-header-count' : 'detail-header'"
        @click="checkedClick(item, index)"
      >
        <div class="header-detail-left">
          <a-checkbox v-model:checked="item.checked" class="check-single"></a-checkbox>
            <a @click="goscan(item)"
              style="margin-left: 8px"
              >{{
                item.title
              }}</a
            >
        </div>
      </div>
      <div class="detail-content">
        <div class="commentator-comment1">
          <div class="commentator">
            <span class="comment">作者：{{ item.author }}</span>
            <span class="comment">创建时间：{{ item.createTime }}</span>
            <span class="comment">发布时间：{{ item.publishTime }}</span>
            <span class="comment">所属栏目：{{ item.channelName }}</span>
          </div>
          <div class="like-box">
            <a-popconfirm
            placement="topRight"
            ok-text="确定"
            cancel-text="取消"
            @confirm="toDetele(item.id)"
          >
            <template #title>
              <p style="width: 197px"> {{props.tabKey == 1 ? '是否移除？' : '是否引用？'}} </p>
            </template>
            <a style="fontSize:14px">  {{ props.tabKey == 1 ? '移除' : '引用' }} </a>
          </a-popconfirm>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, reactive, ref, watch } from "vue";
import { cloneDeep, stubString } from "lodash";
import request from "@/api/index";
import { routerPerm } from "@/utils/common";
//props
const props = defineProps({
  configData: {
    type: Object,
    default: {},
  },
  tabKey: {
    type: Number,
    default: 1,
  },
});
//emit
const emit = defineEmits([
  "checkedClick",
  "toDetele",
]);

//data
const btnPerm = ref<any[]>([]);
const resData = ref(cloneDeep(props.configData.records));
const isOpenReportModel = ref<boolean>(false);
const reporterList = ref<any[]>([]);
const maxHeight = ref<string>("");
const modAlProps: any = reactive({
  width: "M",
  title: "举报",
});
const reason = [
  "营销广告",
  "违法涉政",
  "淫秽色情",
  "网络赌博",
  "诈骗",
  "言论攻击",
  "网络谣言",
  "民族宗教",
  "涉未成年举报",
];
//watch
watch(
  () => props.configData.records,
  (newVal, oldVal) => {
    if (newVal.length) {
      resData.value = cloneDeep(newVal);
      resData.value.length &&
        resData.value.forEach((item: any) => {
          if (item?.sysAdminReplyDto?.comment) {
            item.replyCommentCon = item?.sysAdminReplyDto?.comment;
          } else {
            item.replyCommentCon = "";
          }
        });
    } else {
      resData.value = [];
    }
  },
  { deep: true }
);

//method
const openReporterModel = async (commentId: number) => {
  reporterList.value = await request.fetchCommentCommentReports({ commentId, size: 100 });
  reporterList.value.length &&
    reporterList.value.forEach((item: any) => {
      if (item.reportType) {
        item.reportTypeText = reason[item.reportType];
      } else {
        item.reportTypeText = item.extraMsg;
      }
    });
  isOpenReportModel.value = true;
};

//单击事件
const checkedClick = (item: any, index: number) => {
  emit("checkedClick", item, index);
};

//删除 引用
const toDetele = (id: number) => {
  emit("toDetele", [id]);
};

// 点击标题跳转到浏览页面
const goscan = (item: any) => {
  window.open(item.scanUrl)
};

onMounted(() => {
  btnPerm.value = routerPerm();
  maxHeight.value = `${ document.documentElement.clientHeight - 268 }px`;
  window.onresize = () => {
    maxHeight.value = `${ document.documentElement.clientHeight - 268 }px`;
  };
});
</script>

<style lang="less" scoped>
.data-list {
  display: flex;
  margin-top: 16px;
  flex-direction: column;
  overflow-y: scroll;

  .data-item {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(0, 0, 0, 0.06);

    .detail-header {
      display: flex;
      flex-direction: row;
      align-items: center;
      padding: 6px 9px;
      background: rgba(0, 0, 0, 0.02);

      .header-detail-left {
        display: flex;
        flex-direction: row;
        align-items: center;
      }

      .header-detail-right {
        display: flex;
        flex-direction: row;
        align-items: center;

        .reports-name {
          display: block;
          font-size: 14px;
          line-height: 14px;
          color: #000000d9;
        }

        .reports-time {
          display: block;
          font-size: 14px;
          line-height: 14px;
          color: #000000d9;
        }
      }

      .dots {
        padding-right: 40px;
        color: #000000d9;
        font-size: 14px;
        display: block;
        line-height: 0px;
        width: 12px;
        height: 6px;
      }

      .time {
        display: flex;
        flex-direction: row;
        align-items: center;
        margin-left: 40px;
        font-size: 14px;

        span {
          margin-left: 8px;
          color: #00000073;
        }
      }

      .anony-box {
        font-size: 14px;
        line-height: 14px;
        color: #000000d9;
      }

      .ip-box {
        display: flex;
        flex-direction: row;
        align-items: center;
        line-height: 14px;
        font-size: 14px;
        margin-left: 2px;
      }

      .status {
        margin-left: 8px;
        padding: 5px 8px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 2px;
        font-size: 12px;
        line-height: 12px;
      }

      .status4 {
        display: flex;
        flex-direction: row;
        align-items: center;

        .icon-report {
          font-size: 16;
          display: block;
          line-height: 16px;
          color: #ff4d4fff;
        }

        span {
          color: #ff4d4fff;
          font-size: 14px;
          display: block;
          line-height: 14px;
          margin-left: 4px;
        }
      }

      .status1 {
        color: #d46b08;
        background: #fff7e6;
        border: 1px solid #ffd591;
      }

      .status2 {
        color: #389e0d;
        background: #f6ffed;
        border: 1px solid #b7eb8f;
      }

      .status3 {
        color: #cf1322;
        background: #fff1f0;
        border: 1px solid #ffa39e;
      }

      .check-single {
        line-height: 16px;
      }

      a {
        display: block;
        font-size: 14px;
        line-height: 14px;
      }

      .iconfont {
        display: block;
        height: 16px;
        line-height: 16px;
      }
    }

    .detail-header-count {
      justify-content: space-between;
    }

    .detail-content {
      display: flex;
      flex-direction: column;
      padding: 8px;

      .commentator-comment1 {
        display: flex;
        flex-direction: row;
        justify-content: space-between;

        .commentator {
          display: flex;
          // flex-direction: row;
          margin-right: 24px;

          .comment-left {
            width: 40px;
            font-size: 14px;
            color: rgba(0, 0, 0, 0.45);
          }

          .comment {
            margin-left: 15px;
            
            font-size: 14px;
            color: rgba(0, 0, 0, 0.7);
          }
        }

        .like-box {
          width: 40px;
          height: 18px;
          line-height: 21px;
          .icon-a-Firstpush {
            font-size: 20px;
            line-height: 20px;
          }
        }
      }

      .comment-box {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        margin-bottom: 16px;

        .commentator-comment {
          margin-top: 12px;
          display: flex;
          flex-direction: row;
          width: 1078px;

          .commentator {
            font-size: 14px;
            color: rgba(0, 0, 0, 0.45);
          }

          .comment {
            margin-left: 12px;
            font-size: 14px;
            color: rgba(0, 0, 0, 0.85);
          }
        }
      }

      .replied {
        display: flex;
        flex-direction: row;
        justify-content: space-between;

        .replied-content-box {
          margin-right: 24px;
          display: flex;
          flex-direction: row;
          width: 100%;

          .replied-text {
            min-width: 36px;
            font-size: 14px;
            height: 22px;
            color: rgba(0, 0, 0, 0.45);
          }

          .replied-content-change {
            margin-left: 12px;
            display: flex;
            flex-direction: column;
            align-items: end;
            width: calc(100% - 44px);

            .text-input {
              width: 100%;
              position: relative;
            }

            .buttons {
              margin: 8px 0;
              display: flex;
              flex-direction: row;
              align-items: center;

              .button {
                display: flex;
                flex-direction: row;
                align-items: center;
                justify-content: center;
                width: 44px;
                height: 24px;
              }
            }
          }

          .replied-content {
            margin-bottom: 16px;
            margin-left: 12px;
            font-size: 14px;
            color: rgba(0, 0, 0, 0.85);
          }
        }

        .like-box {
          display: flex;
          flex-direction: row;
          height: 22px;

          .iconfont {
            display: block;
            line-height: 18px;
            font-style: 18px;
          }

          .like-count {
            margin-left: 6px;
            font-size: 14px;
            color: rgba(0, 0, 0, 0.85);
          }
        }
      }
    }

    .detail-footer {
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: space-between;
      padding: 5px 16px;
      border-top: 1px solid rgba(0, 0, 0, 0.06);

      .footer-left {
        display: flex;
        flex-direction: row;
        align-items: center;

        .channal-name {
          display: block;
          font-size: 14px;
          line-height: 14px;
          color: #00000073;
          max-width: 348px;
          text-overflow: ellipsis;
          white-space: nowrap;
          overflow: hidden;

          .title {
            color: #000000d9;
          }

          .title:hover {
            cursor: pointer;
            color: #1f6ded;
          }
        }

        a {
          font-size: 14px;
          margin-left: 24px;
        }

        .all-count {
          margin-left: 4px;
          color: #00000073;
          font-size: 14px;
        }
      }

      .footer-right {
        display: flex;
        flex-direction: row;

        a {
          font-size: 14px;
          margin-right: 16px;
        }

        a:last-child {
          margin-right: 0;
        }
      }
    }

    .detail-content-footer {
      justify-content: end;
    }
  }

  .data-item:first-child {
    margin-top: 0;
  }
}

::v-deep(.ant-input-textarea-show-count > .ant-input) {
  height: 32px;
}

::v-deep(.ant-table-tbody > tr > td:last-child) {
  text-align: right;
}

::v-deep(.ant-badge-count, .ant-badge-dot, .ant-badge
    .ant-scroll-number-custom-component) {
  top: -12px;
  right: -30px;
}

::v-deep(.ant-input-textarea-show-count::after) {
  bottom: 8px;
}
</style>
<style>
@media screen and (max-width: 1439px) and (min-width: 1280px) {
  .marginL40_16 {
    margin-left: 16px;
  }
}

@media screen and (min-width: 1440px) {
  .marginL40_16 {
    margin-left: 40px;
  }
}

#commentmanage-container .table-bottom_fiexd {
  padding: 0 36px;
}
</style>
